#ifndef __SYS_H
#define __SYS_H	  
#include "gd32f4xx.h"
//////////////////////////////////////////////////////////////////////////////////	 

////////////////////////////////////////////////////////////////////////////////// 	  					

#define BITMEM_BASE       0x20000000UL
#define BITBAND_BASE      0x22000000UL
#define BITPHMEM_BASE     0x40000000UL
#define BITPHBAND_BASE    0x42000000UL

#define MEM32(addr)       (*(uint32_t *)(uint32_t)(addr))

#define AliasAddr(addr,bitnum) (BITBAND_BASE + (addr-BITMEM_BASE)*32+ bitnum*4)
#define PhAliasAddr(addr,bitnum) (BITPHBAND_BASE + (addr-BITPHMEM_BASE)*32+ bitnum*4)


#define PAOout(n)  MEM32(PhAliasAddr(GPIOA+0x14,n))  //Output
#define PAIn(n)    MEM32(PhAliasAddr(GPIOA+0x10,n)   //Input

#define PBOut(n)   MEM32(PhAliasAddr(GPIOB+0x14,n))  //Output 
#define PBIn(n)    MEM32(PhAliasAddr(GPIOB+0x10,n)   //Input 

#define PCOut(n)   MEM32(PhAliasAddr(GPIOC+0x14,n))  //Output 
#define PCIn(n)    MEM32(PhAliasAddr(GPIOC+0x10,n)   //Input 

#define PDOut(n)   MEM32(PhAliasAddr(GPIOD+0x14,n))  //Output 
#define PDIn(n)    MEM32(PhAliasAddr(GPIOD+0x10,n)   //Input 

#define PEOut(n)   MEM32(PhAliasAddr(GPIOE+0x14,n))  //Output 
#define PEIn(n)    MEM32(PhAliasAddr(GPIOE+0x10,n)   //Input 

#define PFOut(n)   MEM32(PhAliasAddr(GPIOF+0x14,n))  //Output 
#define PFIn(n)    MEM32(PhAliasAddr(GPIOF+0x10,n)   //Input 

#define PGOut(n)   MEM32(PhAliasAddr(GPIOG+0x14,n))  //Output 
#define PGIn(n)    MEM32(PhAliasAddr(GPIOG+0x10,n)   //Input 

#endif











